//
//  EJCommentBar.m
//  EJiangOSbeta
//
//  Created by 刘爽 on 2019/10/22.
//  Copyright © 2019 Joyssom. All rights reserved.
//

#import "EJCommentBar.h"
#import <Masonry/Masonry.h>
//#import <UITextView+Placeholder/UITextView+Placeholder.h>
#import "UITextView+Placeholder.h"

@implementation EJCommentBar

- (instancetype)init {
    self = [super init];
    if (self) {
        [self commonInit];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self commonInit];
    }
    return self;
}

- (void)commonInit {
    self.backgroundColor = [UIColor whiteColor];
    
    _topLine = [[UIView alloc] init];
    _topLine.backgroundColor = [UIColor colorWithRed:(227 / 255.0) green:(227 / 255.0) blue:(227 / 255.0) alpha:1];
    [self addSubview:_topLine];
    [_topLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
        make.height.mas_equalTo((1 / [UIScreen mainScreen].scale));
    }];
    
    
    [self addSubview:self.textView];
    
    [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(14);
        make.top.equalTo(self.mas_top).offset(7);
        make.height.mas_greaterThanOrEqualTo(36);
        make.bottom.equalTo(self.mas_bottom).offset(-8);
    }];
    
    [self addSubview:self.sendButton];
    
    [_sendButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-23);
        make.left.equalTo(_textView.mas_right).offset(8);
        make.size.mas_equalTo(CGSizeMake(30, 30));
        make.bottom.equalTo(_textView.mas_bottom).offset(-3);
    }];
    
    [self layoutIfNeeded];
}

- (UITextView *)textView {
    if (!_textView) {
        _textView = [[UITextView alloc] init];
        _textView.font = [UIFont systemFontOfSize:14];
        _textView.textColor = [UIColor colorWithRed:(34 / 255.0) green:(34 / 255.0) blue:(34 / 255.0) alpha:1];
        _textView.placeholderColor = [UIColor colorWithRed:(204 / 255.0) green:(204 / 255.0) blue:(204 / 255.0) alpha:1];
        _textView.layer.cornerRadius = 3;
        _textView.layer.masksToBounds = YES;
        _textView.textContainerInset = UIEdgeInsetsMake(9, 15, 9, 15);
        _textView.contentInset = UIEdgeInsetsZero;
        _textView.textContainer.lineFragmentPadding = 0;
        _textView.layoutManager.allowsNonContiguousLayout = NO;
        _textView.placeholder = @"写评论...";
        _textView.scrollEnabled = NO;
        
        _textView.backgroundColor = [UIColor colorWithRed:(247 / 255.0) green:(248 / 255.0) blue:(251 / 255.0) alpha:1];
        
        _textView.layer.cornerRadius = 3;
        _textView.layer.masksToBounds = YES;
    }
    return _textView;
}

- (UIButton *)sendButton {
    if (!_sendButton) {
        _sendButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_sendButton setImage:[UIImage imageNamed:@"comment_send"] forState:UIControlStateNormal];
        [_sendButton setImage:nil forState:UIControlStateDisabled];
    }
    return _sendButton;
}

@end
